using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ChordCreator.Services.ConfigurationServices
{
    /// <summary>
    /// This class is used to store information about
    /// </summary>
    public class ScaleXML
    {

        [XmlAttribute]
        public string Name
        { get; set; }

        [XmlIgnore]
        public int[] Degrees
        { get; set; }

        [XmlAttribute]
        public string ScaleDegrees
        {

            get
            {
                StringBuilder builder = new StringBuilder();
                foreach (var i in Degrees)
                {
                    builder.Append(i);
                    builder.Append(',');
                }
                return builder.ToString().Trim(',');
            }
            set
            {
                string val = value.Trim();
                string[] strings = val.Split(XmlConfiguration.Seperators, StringSplitOptions.RemoveEmptyEntries);
                List<int> result = new List<int>();
                try
                {
                    foreach (string str in strings)
                    {
                        result.Add(int.Parse(str));
                    }
                }
                catch (FormatException)
                {
                    throw new XmlException("Scale degrees should be in a,b,c,d format");
                }
                Degrees = result.ToArray();
            }
        }
    }
}